package com.hmall.order.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqDelayConfig {

    /**
     * 延迟消息交换机delayExchange
     */
    @Bean
    public DirectExchange delayExchange() {
        return ExchangeBuilder
                .directExchange("delayExchange")
                .delayed()
                .durable(true)
                .build();
    }

    /**
     * 延迟消息队列
     */
    @Bean
    public Queue delayQueue() {
        return new Queue("delayQueue", true);
    }

    /**
     * 延迟消息队列绑定交换机
     */
    @Bean
    public Binding delayQueueBinding() {
        return BindingBuilder.bind(delayQueue()).to(delayExchange()).with("delayKey");
    }
}
